/*
 ------------------------------------------------------------------------------
 Copyright (C) 2013 Eternal Games.

 This file is part of the GLQuake source code.

 The GLQuake source code is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or (at your
 option) any later version.

 The GLQuake source code is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 more details.

 You should have received a copy of the GNU General Public License along with
 the GLQuake source code; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 ------------------------------------------------------------------------------
*/


//
// system.h - framework used by dynamic-link libraries
//


#ifndef __FRAMEWORK_SYSTEM_H__
#define __FRAMEWORK_SYSTEM_H__


/*
 ==============================================================================

 System Interface:

 Portable interface to non-portable system services.

 ==============================================================================
*/

enum cpuId_t {
	CPUID_GENERIC					= BIT(0),	// Unrecognized processor
	CPUID_AMD						= BIT(1),	// AMD processor
	CPUID_INTEL						= BIT(2),	// Intel processor
	CPUID_POWERPC					= BIT(3),	// PowerPC processor
	CPUID_MMX						= BIT(4),	// MMX
	CPUID_MMX_EXT					= BIT(5),	// Extended MMX
	CPUID_3DNOW						= BIT(6),	// 3DNow!
	CPUID_3DNOW_EXT					= BIT(7),	// Extended 3DNow!
	CPUID_SSE						= BIT(8),	// Streaming SIMD Extensions
	CPUID_SSE2						= BIT(9),	// Streaming SIMD Extensions 2
	CPUID_SSE3						= BIT(10),	// Streaming SIMD Extensions 3
	CPUID_SSSE3						= BIT(11),	// Supplemental Streaming SIMD Extensions 3
	CPUID_SSE41						= BIT(12),	// Streaming SIMD Extensions 4.1
	CPUID_SSE42						= BIT(13),	// Streaming SIMD Extensions 4.2
	CPUID_SSE4A						= BIT(14),	// Streaming SIMD Extensions 4A
	CPUID_XOP						= BIT(15),	// XOP
	CPUID_FMA4						= BIT(16),	// Fused Multiply-Add 4
	CPUID_AVX						= BIT(17),	// Advanced Vector Extensions
	CPUID_ALTIVEC					= BIT(18)	// AltiVec
};

// Functions exported by the engine
struct glqSystem_t {
	// Returns a list of files and subdirectories that match the given
	// extension (which must include a leading '.' and must not contain
	// wildcards).
	// If extension is NULL, all the files will be returned and all the
	// subdirectories ignored.
	// If extension is "/", all the subdirectories will be returned and all the
	// files ignored.
	// The returned list can optionally be sorted.
	const char **			(*ListFiles)(const char *directory, const char *extension, bool sort, int *numFiles);

	// Returns a list of files and subdirectories that match the given filter.
	// The returned list can optionally be sorted.
	const char **			(*ListFilteredFiles)(const char *directory, const char *filter, bool sort, int *numFiles);

	// Frees the memory allocated by ListFiles and ListFilteredFiles
	void					(*FreeFileList)(const char **fileList);

	// Creates the given directory
	void					(*CreateDirectory)(const char *directory);

	// Removes the given directory, including all the subdirectories and files
	// contained inside
	void					(*RemoveDirectory)(const char *directory);

	// Returns the current directory
	const char *			(*CurrentDirectory)();

	// Returns the default base directory
	const char *			(*DefaultBaseDirectory)();

	// Returns the default save directory
	const char *			(*DefaultSaveDirectory)();

	// Returns the amount of free space (in megabytes) available on the disk
	// containing the given directory
	int						(*DiskFreeSpace)(const char *directory);

	// Loads the given dynamic library
	void *					(*LoadLibrary)(const char *libPath);

	// Frees the given dynamic library
	void					(*FreeLibrary)(void *libHandle);

	// Gets the address of the given procedure from the given dynamic library
	void *					(*GetProcAddress)(void *libHandle, const char *procName);

	// Returns information about the CPU
	int						(*GetProcessorId)();
	int						(*GetProcessorCount)();
	const char *			(*GetProcessorString)();

	// Causes a breakpoint exception
	void					(*DebugBreak)();

	// Yields CPU time for the given number of milliseconds
	void					(*Sleep)(int msec);

	// Milliseconds should only be used for profiling purposes, any game
	// related timing information should come from event timestamps
	int						(*Milliseconds)();

	// For accurate performance testing
	longlong				(*ClockTicks)();
	longlong				(*ClockTicksPerSecond)();

	// Returns the handle to the application instance
	void *					(*GetInstanceHandle)();

	// Returns the handle to the application icon
	void *					(*GetIconHandle)();

	// Grabs text from the clipboard if available.
	// The returned pointer must be freed by the caller.
	const char *			(*GetClipboardText)();

	// Sends text to the clipboard
	void					(*SetClipboardText)(const char *text);

	// Starts the given process and optionally quits the program immediately
	void					(*StartProcess)(const char *exePath, bool quit);

	// Opens the given URL and optionally quits the program immediately
	void					(*OpenURL)(const char *url, bool quit);
};


#endif	// __FRAMEWORK_SYSTEM_H__